package cn.icanci.ladybird.controller;

import cn.icanci.ladybird.common.util.BaseHeadImagesUtils;
import cn.icanci.ladybird.common.util.CommonUtils;
import cn.icanci.ladybird.pojo.entity.Admin;
import cn.icanci.ladybird.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author: icanci
 * @date: Created in 2020/10/7 7:21
 * @classAction: 管理员添加用户的 Controller
 */
@Controller
@RequestMapping("/api/v1/pri/admin")
public class AdminDataForAdminAccountController {
    @Autowired
    private AdminService adminService;
    @Autowired
    private AdminDataListController adminDataListController;

    @RequestMapping("/admin-add")
    public String adminAdd() {
        return "admin/admin-add";
    }

    @RequestMapping("/admin-add-insert")
    public String adminAddInsert(Model model, Admin admin) {
        admin.setAdminPassword(CommonUtils.MD5(admin.getAdminPassword()));
        admin.setAdminHeadImg(BaseHeadImagesUtils.getRandomHeadImage());
        adminService.insert(admin);
        return adminDataListController.adminList(model, null, null);
    }
}

